/**********************************************************************************************************************
 * @file    nmea_gga.c
 * @author  Queclink Jason.huang
 * @date    2019-01-02
 * @brief   NMEA-GGA frame source.
 *
 * Copyright (C) 2018 Queclink Wireless Solutions (ShenZhen) Co., Ltd. All Rights Reserved.
 *
 * @attention
 *
 * @usage
 *
 *********************************************************************************************************************/

/* includes ---------------------------------------------------------------------------------------------------------*/
#include <stdlib.h>
#include <string.h>
#include "nmea.h"

/*
 * @brief  GGA消息解析
 * @note
 * @param  argc: [I], 消息分割后字符串数量
 *         argv: [I], 字符串地址列表
 * @retval none
 */
void nmea_gga_parse(int argc, char *argv[])
{
    int gps_status = 0;         /* gps 状态0=未定位，1=非差分定位，2=差分定位，3=无效PPS，6=正在估算*/
    nmea_protocol_parse_t *nmea_ptr;
    gnss_task_manage_t * gnss_manage = get_gnss_manage();

    nmea_ptr = get_nmea_manage_context();
    if (NULL == nmea_ptr)
        return;

    nmea_ptr->recv_nmea_msg |= GGA_MASK;
    gps_status = atoi(argv[6]);
    if(gps_status)
        nmea_ptr->stream_valid_mask |= GGA_MASK; /*判断是否定位成功(GGA语句是否有效) */
    else
        nmea_ptr->stream_valid_mask &= (~GGA_MASK);

    /*水平精度因子*/
    if(strlen(argv[8]) != 0)
        nmea_ptr->raw_info.hdop = (float)atof(argv[8]);
    else
        nmea_ptr->raw_info.hdop = 0;

    /*海拔高度*/
    if(strlen(argv[9]) != 0)
        nmea_ptr->raw_info.altitude = (float) atof(argv[9]);
    else
        nmea_ptr->raw_info.altitude = 0;
    if(!gnss_manage->gnss_info.is_uart_rx_ok){
        gnss_manage->gnss_info.is_uart_rx_ok = true;
    }
}
